package com.sali.disruptor;

import cn.hutool.json.JSONObject;
import com.lmax.disruptor.WorkHandler;
import com.sali.disruptor.entity.MessageEvent;
import com.sali.statistics.MockMessageStatistics;
import lombok.Builder;
import lombok.extern.slf4j.Slf4j;

/**
 * @description:
 * @author: sali
 * @date: 2025/2/22 下午3:23.
 * @version: 1.0
 */
@Slf4j
@Builder
public class MessageConsumer implements WorkHandler<MessageEvent<JSONObject>> {
    @Override
    public void onEvent(MessageEvent<JSONObject> messageEvent) throws Exception {
        JSONObject message = messageEvent.getMessage();
        if (message == null) {
            return;
        }

        MockMessageStatistics.getParseMsgCount().incrementAndGet();

        log.info("consumer 接收到的数据内容: {}", message);

        message.clear();
    }
}
